import { defineStore } from 'pinia'
import { UserInfoData } from '@/api/user/type'
import { userInfo } from './types/user'

export const useUserStore = defineStore('User', {
  state: (): userInfo => {
    // 用户信息
    return {
      avatar: '',
      name: '',
      buttons: [],
      routes: [],
      token: '',
    }
  },
  //   异步，逻辑
  actions: {
    // 设置用户信息
    SET_USERINFO(userInfo: UserInfoData) {
      this.avatar = userInfo.avatar || ''
      this.name = userInfo.name || ''
      this.buttons = userInfo.buttons || []
      this.routes = userInfo.routes || []
    },
    // 清除用户信息
    CLEAR_USERINFO() {
      this.avatar = ''
      this.name = ''
      this.buttons = []
      this.routes = []
      this.token = ''
    },
  },
})
